<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="店铺名称" prop="storeName">
        <el-input style="width: 160px" v-model="queryParams.storeName" placeholder="店铺名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="开户人" prop="fullName">
        <el-input style="width: 120px" v-model="queryParams.fullName" placeholder="开户人姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="银行卡号" prop="collectionAccountNo">
        <el-input style="width: 200px" v-model="queryParams.collectionAccountNo" placeholder="银行卡号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="手机号" prop="collectionAccountPhone">
        <el-input style="width: 150px" v-model="queryParams.collectionAccountPhone" placeholder="银行卡预留手机号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="提现时间" prop="dateRange">
        <el-date-picker
          style="max-width: 240px"
          v-model="dateRange"
          type="daterange"
          size="small"
          align="right"
          unlink-panels
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="审核状态" prop="state">
        <el-select style="width: 120px" v-model="queryParams.state" placeholder="审核状态" clearable >
          <el-option v-for="dict in dict.type.store_state_apply" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" />
    </el-row>

    <el-table v-loading="loading" :data="withdrawalList">
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="店铺" align="center" prop="storeName" />
      <el-table-column label="开户人" align="center" prop="fullName" />
      <el-table-column label="身份证号" align="center" prop="collectionIdCardNo" />
      <el-table-column label="银行预留手机号" align="center" prop="collectionAccountPhone" />
      <el-table-column label="银行名称" align="center" prop="collectionAccountName" />
      <el-table-column label="银行卡号" align="center" prop="collectionAccountNo" />
      <el-table-column label="开户行地址" align="center" prop="addressText" />
      <el-table-column label="提现金额" align="center" prop="amount" />
      <el-table-column label="手续费" align="center" prop="amountService" />
      <el-table-column label="到账金额" align="center" prop="amountReal" />
      <el-table-column label="提现时间" align="center" prop="createTime" width="100" />
      <el-table-column label="审核状态" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.store_state_apply" :value="scope.row.state" />
        </template>
      </el-table-column>
      <el-table-column label="审核备注" align="center" prop="rejectRemark" />
      <el-table-column label="审核时间" align="center" prop="applyTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" v-if="scope.row.state == 0" @click="handleApply(scope.row)">审核</el-button>
          <div v-else>-</div>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog title="提现申请审核" width="530px" :visible.sync="dialogFormVisible">
      <el-form :model="form" label-width="80px" ref="form" :rules="rules">
        <el-form-item label="审核状态" prop="state">
          <el-radio-group v-model="form.state">
            <el-radio v-for="dict in storeStateApply" :key="dict.value" :label="dict.value">{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="驳回原因" prop="rejectRemark" v-if="form.state == 2">
          <el-input style="width: 400px" type="textarea" placeholder="请输入内容" v-model="form.rejectRemark" maxlength="50" show-word-limit rows="4" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitApply" :loading="loadingBtn">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { withdrawalApproval, withdrawalPage } from "@/api/store/store";
export default {
  name: "Store",
  dicts: ["store_state_apply"],
  data() {
    return {
      dialogFormVisible: false,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      withdrawalList: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        fullName: "",
        collectionAccountNo: "",
        state: "",
        collectionAccountPhone: "",
        beginCreateTime: "",
        endCreateTime: "",
      },
      // 日期范围
      dateRange: [],
      form: {
        id: "", //审核id
        state: "",
        rejectRemark: "",
      },
      storeStateApply: [
        { value: 1, label: "通过" },
        { value: 2, label: "驳回" },
      ],
      rules: {
        state: [
          { required: true, message: "请选择审核状态", trigger: "change" },
        ],
        rejectRemark: [
          { required: true, message: "请填写驳回原因", trigger: "blur" },
        ],
      },
      loadingBtn: false,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询店铺列表 */
    getList() {
      this.loading = true;
      if (!Array.isArray(this.dateRange)) {
        this.dateRange = [];
      }
      this.queryParams.beginCreateTime = this.dateRange[0];
      this.queryParams.endCreateTime = this.dateRange[1];
      withdrawalPage(this.queryParams).then((response) => {
        this.withdrawalList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //审核
    handleApply(item) {
      this.form.id = item.id;
      this.dialogFormVisible = true;
    },
    //确认审核
    submitApply() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.loadingBtn = true;
          withdrawalApproval(this.form).then((res) => {
            if (res.code === 200) {
              this.$message.success("操作成功");
              this.resetForm("form");
              this.dialogFormVisible = false;
              this.getList();
            } else {
              this.resetForm("form");
              this.$message.error(res.msg);
            }
            this.loadingBtn = false;
          });
        }
      });
    },
    cancel() {
      this.resetForm("form");
      this.dialogFormVisible = false;
    },
  },
};
</script>
<style lang="scss" scoped></style>
